<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>交易统计图</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/echarts/echarts.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            width: 100%;
            height: 1030px;
        }
        .list{
            width: 1650px;
            height: 50px;
            margin-left: 20px;
            background-color:rgb(243,243,243);
        }
        .list-left{
            width: 150px;
            height: 30px;
            margin-top: 10px;
            float: left;
        }
        .list-left-left{
            width: 10px;
            height: 30px;
            float: left;
            background: green;
        }
        .list-left-right{
            width: 120px;
            height: 30px;
            font-size: 14px;
            line-height: 30px;
            float: left;
            text-indent: 5px;
        }
        .list-right{
            float: right;
            margin-top: 5px;
            margin-right: 45px;
        }
        .query{
            width: 1650px;
            height: 100px;
            margin-top: 20px;
            margin-left: 20px;
        }
        .layui-col-md11{
            width: 100%;
        }
        .layui-card-header{
            background-color:rgb(243,243,243);
        }
        .record{
            width: 1650px;
            height: 821px;
            margin-top: 40px;
            margin-left: 20px;
            background-color:rgb(243,243,243);
        }
        img{
            width: 100px;
            height: 116px;
        }
        .layui-card-body td{
            width: 300px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            border: 1px solid #F3F3F3;
        }
    </style>
</head>
<body>
<div class="box">
    <div class="list">
        <div class="list-left">
            <div class="list-left-left"></div>
            <p class="list-left-right">课程交易统计图</p>
        </div>
        <div class="list-right">
            <div class="list-right-left layui-btn layui-icon layui-icon-refresh" onclick="refresh()">&nbsp;刷新</div>
            <div class="list-right-right layui-btn layui-icon layui-icon-left" onclick="goBack()">&nbsp;返回</div>
        </div>
    </div>
    <div class="layui-row query">
        <div class="layui-col-md11">
            <div class="layui-card headerCenter">
                <div class="layui-card-header backColor">
                    <i class="layui-icon">&#xe613;</i>
                    课程交易列表
                </div>
                <div class="layui-card-body">
                    <table>
                        <tr id="product">
                            <td>课程名</td>
                        </tr>
                        <tr style="background:#F3F3F3" id="hits">
                            <td>销售数量</td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!--Echars-->
    <div class="record">
        <div style="float: left;">
            <p style="margin-left: 20px;font-size: 15px;font-weight: 600">课程交易统计图</p>
            <p style="margin-left: 20px;font-size: 12px;color:#D3D3D3">思云产品</p>
        </div>
        <div style="height: 90px;width: 200px; float: right;  text-align: center; margin-top: 25px;margin-right: 100px" id="day">
            <i onclick="circular()" class="layui-icon layui-icon-menu-fill" style="font-size: 20px;margin-right: 5px"></i>
            <i onclick="strip()" class="layui-icon layui-icon-chart" style="font-size: 20px;margin-right: 5px"></i>
            <i onclick="column()" class="layui-icon layui-icon-template-1" style="font-size: 20px;margin-right: 5px"></i>
            <i onclick="refresh()" class="layui-icon layui-icon-refresh" style="font-size: 20px;margin-right: 5px"></i>
            <i onclick="downLoad()" class="layui-icon layui-icon-export" style="font-size: 20px;"></i>
        </div>
        <div id="main" style="width: 1660px; height: 500px;float: left;margin-top: -52px"></div>
    </div>
</div>

<script>
    var categroys = [];
    var titles = [];
    var hits = [];
    layui.use(['jquery','layer','table','form','upload'],function(){
        var $=layui.jquery;
        var layer=layui.layer;

        refresh=function refresh(){
            location.reload();
        }

        $.ajax({
            url: '/SyStatistical/getSaleNum',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                var coursePrimary = data.data;
                console.log(coursePrimary);
                for (var i = 0; i < 5; i++) {
                    $('#product').append('<td>' + coursePrimary[i].courseName + '</td>');
                    $('#hits').append('<td>' + coursePrimary[i].hits + '</td>');
                    //将值存入到新的数组中
                    titles[i] = coursePrimary[i].courseName;
                    hits[i] = coursePrimary[i].hits;
                    var cate = {value: hits[i],name:titles[i]};
                    categroys[i] = cate;
                    circular();
                }
            }
        });

    })
    console.log(categroys);

    //下载Echarts表格
    function downLoad(){
        var canvas = document.getElementsByTagName("canvas")
        if (canvas && canvas.length > 0) {
            var oA = document.createElement("a")
            oA.download = "Echarts图表" + ".png"
            oA.href = canvas[0].toDataURL("image/png")
            document.body.appendChild(oA)
            oA.click()
            oA.remove()
        }
    }

    //扇形统计图
    function circular(){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            tooltip: {},
            series: [
                {
                    type: 'pie',
                    data: categroys,
                    roseType: 'area'
                }
            ],
            xAxis: {
                show: false
            },
            yAxis: {
                show: false
            }
        };

        option && myChart.setOption(option);
    }
    function strip() {
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            tooltip: {},
            xAxis: {
                show: true,
                type: 'category',
                data: titles
            },
            yAxis: {
                show: true,
                type: 'value'
            },
            series: [
                {
                    data: hits,
                    type: 'line'
                }
            ]
        };

        option && myChart.setOption(option);
    }
    function column(){
        var chartDom = document.getElementById('main');
        var myChart = echarts.init(chartDom);
        var option;

        option = {
            tooltip: {},
            xAxis: {
                show: true,
                data: titles
            },
            yAxis: {
                show: true,
            },
            series: [
                {
                    type: 'bar',
                    data: hits
                }
            ]
        };
        option && myChart.setOption(option);
    }


</script>
</body>
</html>